home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Experimental BBS Explossion 3
/
Experimental BBS Explossion III.iso
/
c
/
cp1.zip
/
TIMECHCK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-13
|
5KB
|
156 lines
===========================================================================
BBS: The Abacus * HST/DS * Potterville MI
Date: 05-07-93 (18:03) Number: 98
From: LOUIS LAUZON Refer#: 247
To: ALL Recvd: NO
Subj: Elapsed Time Conf: (36) C Language
---------------------------------------------------------------------------
I wrote this utility and although it solves an immediate need, it needs help bad
ly. :-) It is intended to determine the elapsed time from user keyed start and
end times. It also has the ability to carry over the last end time as the next
start time (+1 second).
I don't have nearly the amount of experience with C as I'd like and I know it is
_very_ sloppy, but could someone explain how to determine the elapsed time if t
he end time is after midnight (24:00). I made it to that point and am stuck.
Also, if anyone could describe a better way of determining the elapsed time rath
er than my endless if() statements, I would be grateful! :-)
/*
** TimeChck.C
** Louis Lauzon
** May 6, 1993
**
** Mix Power C v 2.2.0
*/
#include <stdio.h>
#include <bios.h> /* clrscrn() */
#include <conio.h> /* getche() */
#include <string.h> /* strcmp() */
main()
{
int start_hrs, start_min, start_sec,
end_hrs, end_min, end_sec,
total_hrs, total_min, total_sec,
hold_hrs, hold_min, hold_sec;
int again = 99;
char new[80];
while(again)
{
clrscrn();
if(again == 99) /* First time through program */
{
printf("Starting time: (hh:mm:ss) ");
scanf("%2d%*c%2d%*c%2d", &start_hrs, &start_min, &start_sec);
}
/***************************************/
/* Use last end time or new start time */
/***************************************/
else
{
printf("Press ENTER for starting time = %2d:%02d:%02d\n",
hold_hrs, hold_min, hold_sec+1);
printf("or y for new start time.");
new[0] = getche();
if(strcmp(new[0],"y") == 0 || strcmp(new[0],"Y") == 0)
{
printf("\nStarting time: (hh:mm:ss) ");
scanf("%2d%*c%2d%*c%2d", &start_hrs, &start_min,
&start_sec);
}
/**************************************/
/* Move last end time into start time */
/**************************************/
else
{
start_hrs = hold_hrs;
start_min = hold_min;
start_sec = hold_sec+=1;
}
}
printf("Ending time: (hh:mm:ss) ");
scanf("%2d%*c%2d%*c%2d", &end_hrs, &end_min, &end_sec);
hold_hrs = end_hrs;
hold_min = end_min;
hold_sec = end_sec;
/*****************************/
/* Determine elapsed seconds */
/*****************************/
if(start_sec < end_sec)
total_sec = end_sec - start_sec;
else if(start_sec == end_sec)
total_sec = 0;
else if((start_sec > end_sec) && (start_min < end_min))
{
if(end_sec == 0)
{
total_sec = (60 - start_sec);
}
else
{
total_sec = ((60 - start_sec) + end_sec);
}
end_min-=1;
if(start_hrs < end_hrs)
{
end_hrs-=1;
}
}
else
{
total_sec = ((60 - start_sec) + end_sec);
}
/*****************************/
/* Determine elapsed minutes */
/*****************************/
if(start_min < end_min)
total_min = end_min - start_min;
else if(start_min == end_min)
total_min = 0;
else if((start_min > end_min) && (start_hrs < end_hrs))
{
if(end_min == 0)
{
total_min = (60 - start_min);
}
else
{
total_min = ((60 - start_min) + end_min);
}
end_hrs-=1;
}
/***************************/
/* Determine elapsed hours */
/***************************/
if(start_hrs < end_hrs)
total_hrs = end_hrs - start_hrs;
else if(start_hrs == end_hrs)
total_hrs = 0;
else
total_hrs = 99; /* need to fix code here */
printf("Total Time: %2d:%2d:%2d\n", total_hrs, total_min, total_sec);
puts("Again ? (0 to quit, any integer and ENTER to continue)");
scanf("%d", &again);
}
}
--- Maximus/2 2.01wb
* Origin: The Ozone Layer, Williston, VT. Hst 14.4 / V.32bis (1:325/118)
SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20